package com.homework2;

public class PrivateInner {
    public static void main(String[] args) {
        Outer outer = new Outer();
        outer.show();
        Outer.Inner2 inner2 = new Outer.Inner2();//static的类可以直接new,当然私有的当然不可以直接new
        inner2.inMethod2();
        Outer.Inner inner = new Outer().new Inner();//不是static的类格式有点不一样
                                  //私有的内部类不能在外部用
    }
}
 class Outer{
    private int a = 1;
    public class Inner{
        private int b = 2;
        public void inMethod(){
            System.out.println("这是内部的方法");
            int c = 3;
            System.out.println(a);
            System.out.println(b);
            System.out.println(c);
        }
    }

    public static class Inner2{
        public int d = 5;
        public void inMethod2(){
            System.out.println("这是内部的另一个方法");
        }
    }
    public void show(){
        System.out.println("这是外部类的一个方法");
        Inner inner = new Inner();
        System.out.println(inner.b);//外部类可以直接访问内部private的变量
        System.out.println("=========================");
        inner.inMethod();//
        System.out.println("=========================");
        System.out.println(a);
    }

}